package com.zhaorui.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhaorui.aop.Annotation2;
import com.zhaorui.entity.GzTfJh;
import com.zhaorui.entity.PrdtZ;
import com.zhaorui.entity.ZR;
import com.zhaorui.form.JhQueryForm;
import com.zhaorui.form.StockForm;
import com.zhaorui.mapper.PrdtZMapper;
import com.zhaorui.service.GzTfJhService;
import com.zhaorui.service.PrdtZService;
import com.zhaorui.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("zhStock")
@Slf4j
@CrossOrigin
@Api(tags = "库存看板管理")
public class ZhStockController {
    @Autowired
    private PrdtZService prdtZService;
    @Autowired
    private RedisTemplate redisTemplate;

    // yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1（杭州）为例，Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
    @Value("${OSS.endpoint}")
    String endpoint;
    // 阿里云账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维，请登录RAM控制台创建RAM用户。
    @Value("${OSS.accessKeyId}")
    String accessKeyId;
    @Value("${OSS.accessKeySecret}")
    String accessKeySecret;
    // 填写Bucket名称，例如examplebucket。
    @Value("${OSS.bucketName}")
    String bucketName;


    //控制层对象 不要传给服务层
    @GetMapping("/queryZhStock")
    @ApiOperation("库存看板")
    @Annotation2(tableName = "queryZhStock", optionName = "查询")
    public ZR queryZhStock(StockForm stockForm) {
        log.info ("综合查询:{}", stockForm);
//        Emp emp = new Emp ();
        PrdtZ prdtZ=new PrdtZ();
        //复制vo对象接收的参数到DTO对象中
        BeanUtil.copyProperties (stockForm, prdtZ);
        //分页对象
//        Page page = new Page (currentPage, pagesize);
        List<HashMap> mapList = prdtZService.queryZhStock (prdtZ);
//        PageVo pageVo = new PageVo ();
//        pageVo.setResult (mapList);
//        pageVo.setTotal (page.getTotal ());
        return new ZR (1000, "查询成功", mapList);
    }


    //控制层对象 不要传给服务层
    @GetMapping("/queryZhStock2")
    @ApiOperation("分页库存看板")
    @Annotation2(tableName = "queryZhStock2", optionName = "查询")
    public ZR queryZhStock2(StockForm stockForm, @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage, @RequestParam(name = "pagesize", defaultValue = "5") Integer pagesize) {
        log.info ("综合查询:{}", stockForm);
        PrdtZ prdtZ=new PrdtZ();
        //复制vo对象接收的参数到DTO对象中
        BeanUtil.copyProperties (stockForm, prdtZ);
        //分页对象
        Page page = new Page(currentPage, pagesize);
        List<HashMap> mapList = prdtZService.queryZhStock2 (page,prdtZ);
        PageVo pageVo = new PageVo ();
        pageVo.setResult (mapList);
        pageVo.setTotal (page.getTotal());
        return new ZR (1000, "查询成功", pageVo);
    }
}
